var model=require('../schema/new');
exports.model=model;
exports.update=function(obj,call){
    var id=obj._id;
    delete obj._id;
    model.updateOne({_id:id},obj,call)
}
exports.amount=function(obj,call){
    model.updateOne({_id:obj._id},{
        '$inc':{amount:1}
    },call)
}
exports.create=function(obj,call){
    
    new model(obj).save((err,doc)=>{
        call(err,doc);
    })
        
}
exports.findpage=function(title,pagesize,pageno,call){
    model.find({title:new RegExp(title,'i')}).limit(pagesize).skip((pageno-1)*pagesize).exec((erro,doc)=>{
        model.find({title:new RegExp(title,'i')}).exec((err,result)=>{
            var d={
                list:doc,
                total:result.length,
                pageNo:pageno
            }
            call(err,d);
        })
    });
}
exports.remove=function(id,call){
    model.findOneAndRemove({_id:id},call)
}
